package com.gang.music.core.check;


import com.gang.music.core.interfaces.PermissionCheck;
import com.gang.music.core.shiro.ShiroKit;
import com.gang.music.core.shiro.ShiroUser;
import com.smallchill.core.toolbox.kit.CollectionKit;
import org.springframework.stereotype.Component;

/**
 * 权限自定义检查
 */
@Component
public class PermissionCheckImpl implements PermissionCheck {

	@Override
	public boolean checkPermission(Object[] permissions) {
		ShiroUser user = ShiroKit.getUser();
		if (null == user) {
			return false;
		}
		String join = CollectionKit.join(permissions, ",");
		if(ShiroKit.hasPermission(join)){
			return true;
		}
		return false;
	}

	@Override
	public boolean checkRole(Object[] roles) {
		ShiroUser user = ShiroKit.getUser();
		if (null == user) {
			return false;
		}
		String join = CollectionKit.join(roles, ",");
		
		if(ShiroKit.hasAllRoles(join)){
			return true;
		}
		return false;
	}

}
